package com.atguigu.common.valid;

import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class ListValueValidator implements javax.validation.ConstraintValidator<ListValue,
        Integer> {
    Set<Integer> vals = new HashSet<>();

    @Override
    public void initialize(ListValue constraintAnnotation) {
        final int[] pValues = constraintAnnotation.vals();
        for (int pValue : pValues) {
            this.vals.add(pValue);
        }
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return vals.contains(integer);
    }
}

